package June;

public class Test_16_1 {
    public static void main(String[] args) {
        person1 p = new person1();
        p.name = "jack";
        p.age = 10;

        mytools  tools = new mytools();
        person1 p2 = tools.copyperson1(p);

        System.out.println("p的属性：age = " + p.age + "\t" + "\t" + "name = " + p.name);
        System.out.println("p2的属性：age = " + p2.age + "\t" + "name = " + p2.name);
        System.out.println(p == p2);
    }
}
//编写一个方法copyPerson，可以复制一个Person对象，返回复制的对象。
//克隆对象
//注意要求得到新对象和原来的对象是两个独立的对象，只是他们的属性相同

class person1 {
    String name;
    int age;
}

class mytools {
    public person1 copyperson1(person1 p) {
        person1 p2 = new person1();
        p2.name = p.name;
        p2.age = p.age;
        return p2;
    }
}